<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <meta name="description" content="Violate Responsive Admin Template">
    <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">
    <title>Super Admin Responsive Template</title>
    <!-- CSS -->
    <%@ include file="../inc/new/css.jsp" %>
</head>
<body id="skin-cloth">
<%@ include file="../inc/new/header.jsp" %>
<div class="clearfix"></div>
<section id="main" class="p-relative" role="main">
    <input type="hidden" id="mian_module" value="用户管理">
    <input type="hidden" id="child_module" value="用户审核列表">
    <%@ include file="../inc/new/menu.jsp" %>
    <section id="content" class="container">
        <!-- 查询条件 -->
        <div class="block-area" id="search">
            <div class="row">
                <div class="col-md-2 form-group">
                    <label>姓名：</label>
                    <input type="text" class="input-sm form-control" id="userName" name="userName" placeholder="...">
                </div>
                <div class="col-md-2 form-group">
                    <label>职业：</label>
                    <input type="text" class="input-sm form-control" id="profession" name="profession" placeholder="...">
                </div>
                <div class="col-md-2 form-group">
                    <label>联系方式：</label>
                    <input type="text" class="input-sm form-control" id="mobile" name="mobile" placeholder="...">
                </div>
                <div class="col-md-2 form-group">
                    <label>开始时间：</label>
                    <input type="text" class="form-control input-append date form_datetime"
                           id="startDate" name="startDate" data-rule="required" placeholder="..."/>
                </div>
                <div class="col-md-2 form-group">
                    <label>截止时间：</label>
                    <input type="text" class="form-control input-append date form_datetime"
                           id="endDate" name="endDate" data-rule="required" placeholder="..."/>
                </div>
                <div class="col-md-2 form-group">
                    <label>状态：</label>
                    <select id="statusList" class="select">
                        <option value="">全部</option>
                        <option value="0">待审核</option>
                        <option value="1">审核通过</option>
                        <option value="2">审核失败</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="block-area" id="alternative-buttons">
            <button id="c_search" class="btn btn-alt m-r-5">查询</button>
        </div>

        <div class="block-area">
            <div class="row">
                <ul class="list-inline list-mass-actions">
                    <li class="show-on" style="display: none;">
                        <a onclick="$user.fn.batchDelete(1);" title="批量审核为通过" class="tooltips">
                            <i class="sa-list-refresh"></i>
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <hr class="whiter m-t-20"/>
        <!-- form表格 -->
        <div class="block-area" id="tableHover">
            <table class="table table-bordered table-hover tile" id="dataTables" cellspacing="0" width="100%">
                <thead>
                <tr>
                    <th><input type="checkbox" class="pull-left list-parent-check"/></th>
                    <th>姓名</th>
                    <th>职业</th>
                    <th>联系方式</th>
                    <th>提交时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
            </table>
        </div>

        <div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="pwdModalLabel"
             aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="showText">确定禁用该账号？</h4>
                    </div>
                    <div class="modal-body">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" id="confirm" class="btn btn-primary">确定
                        </button>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
        </div>

    </section>
    <br/><br/>
</section>
<!-- JS -->
<%@ include file="../inc/new/foot.jsp" %>

<script>
    $user = {
        v: {
            list: [],
            dTable: null,
            userId: 0
        },
        fn: {
            init: function () {
                $user.fn.dataTableInit();

                $("#c_search").click(function () {
                    $user.v.dTable.ajax.reload();
                });
            },
            dataTableInit: function () {
                $user.v.dTable = $leoman.dataTable($('#dataTables'), {
                    "processing": true,
                    "serverSide": true,
                    "searching": false,
                    "ajax": {
                        "url": "${contextPath}/admin/user/check/list",
                        "type": "POST"
                    },
                    "columns": [
                        {
                            "data": "id",
                            "render": function (data) {
                                return "<input type='checkbox' class='pull-left list-check' value=" + data + ">";
                            }
                        },
                        {"data": "userName"},
                        {"data": "profession"},
                        {"data": "mobile"},
                        {
                            "data": "createDate",
                            render: function (data) {
                                return new Date(data).format("yyyy-MM-dd hh:mm:ss")
                            }
                        },
                        {
                            "data": "status",
                            render: function (data) {
                                if (data == 0) {
                                    return "待审核";
                                } else if (data == 1) {
                                    return "审核通过";
                                } else if (data == 2) {
                                    return "审核失败";
                                }
                            }
                        },
                        {
                            "data": null,
                            "render": function (data) {
                                var detail = "<button title='查看' class='btn btn-primary btn-circle detail' onclick='$user.fn.detail(" + data.id + ")'> " +
                                        "<i class='fa fa-eye'></i></button>&nbsp;&nbsp;";
                                if (data.status == 0) {
                                    detail += "<button title='审核通过' class='btn btn-success btn-circle check' onclick='$user.fn.changeStatus(" + data.id + ",1)'> " +
                                            "<i class='fa fa-check'></i></button>&nbsp;&nbsp;";
                                    detail += "<button title='审核不通过' class='btn btn-danger btn-circle check' onclick='$user.fn.changeStatus(" + data.id + ",2)'> " +
                                            "<i class='fa fa-times'></i></button>";
                                }

                                return detail;
                            }
                        }
                    ],
                    "fnServerParams": function (aoData) {
                        aoData.userName = $("#userName").val();
                        aoData.profession = $("#profession").val();
                        aoData.mobile = $("#mobile").val();
                        aoData.startDate = $("#startDate").val();
                        aoData.endDate = $("#endDate").val();
                        aoData.status = $("#statusList option:selected").val();
                    }
                });
            },
            rowCallback: function (row, data) {
                $('td', row).last().find(".check").click(function () {
                    var checkbox = $('td', row).first().find("input[type='checkbox']");
                    $user.fn.give(checkbox, [data.id]);
                });
            },
            "detail": function (userId) {
                window.location.href = "${contextPath}/admin/user/check/info?id=" + userId;
            },
            "changeStatus": function (id, status) {
                if (status == 1) {
                    $('#showText').html('确定审核该用户的申请为通过？');
                } else {
                    $('#showText').html('确定审核该用户的申请为不通过？');
                }

                $("#delete").modal("show");
                $('#confirm').click(function () {
                    $leoman.ajax("${contextPath}/admin/user/changeCheckStatus", {
                        "id": id,
                        "status": status
                    }, function (result) {
                        if (result == 1) {
                            $common.fn.notify("操作成功", "success");
                            $("#delete").modal("hide");
                            $user.v.dTable.ajax.reload();
                        } else {
                            $common.fn.notify("操作失败", "error");
                        }
                    });
                });
            },
            "give": function (id) {
                if (id != null) {
                    $("#infoModal").modal("show");
                    $('#num').val(0);
                    $user.v.userId = id;
                }
            },
            batchDelete: function (status) {
                var checkBox = $("#dataTables tbody tr").find('input[type=checkbox]:checked');
                var ids = checkBox.getInputId();
                $.ajax({
                    url: "${contextPath}/admin/user/batchCheck",
                    data: {
                        "ids": JSON.stringify(ids),
                        "status": status
                    },
                    type: "post",
                    dataType: "json",
                    success: function (result) {
                        if (result == 1) {
                            $common.fn.notify("操作成功", "success");
                            $user.v.dTable.ajax.reload();
                            return;
                        } else {
                            $common.fn.notify("操作失败", "error");
                        }
                    }
                });
            }
        }
    }
    $(function () {
        $user.fn.init();
    })
</script>
<script>
    $('.form_datetime').datetimepicker({
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: true,
        format: 'yyyy-mm-dd hh:ii:ss'
    });
</script>
</body>
</html>

